$(function(){
    var user = localStorage.getItem("user")
    if(user){
        $(".user").html(user)
        $(".login").remove()
        $(".register").remove()
        $(".logininfo").html('<a href="#" class="login-out">退出</a>')
        
    }
    $(".logininfo").on("click",".login-out",function(){
        localStorage.removeItem("user")
        window.location.reload();
    })
    //ajax获取数据
    var shoptype = getUrlParam("shoptype")
    console.log(shoptype)
    if (shoptype == null) {
        shoptype = 1
    }
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURI(r[2]);
        }
        return null;
    }
    
    $.ajax({
        url:"http://localhost/yidianzu/API/list_data.php",
        data:{shoptype:shoptype},
        dataType:"json",
        success:function(data){
            console.log(data)
            var html = ""
            for(var i = 0; i<data.length;i++){
                html +=`
                    <li>
                    <a href="./detail.html?t_id=${data[i].Id}" target="_blank">
                        <div class="img-box">
                            <img class="product-img"
                                src="${data[i].img_url}">
                            <i class="icon-new-product-02"></i>
                        </div>
                        <h3 title="${data[i].title}">${data[i].title}</h3>
                        <div class="price">

                            <span>${data[i].price}
                                </span>
                        </div>
                    </a>
                    </li>
                `
            }
            $(".contentUl").html(html)
        }

    })
})